<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class CropCategory extends BaseModel
{
    protected $table = 'evt_crops_category';

    public function edit($data = [], &$error = '', $is_sql = false)
    {
        // 基础参数设置
        $id = isset($data[$this->getPk()]) ? (int)$data[$this->getPk()] : 0;

        if(!$id) {
            if (self::where('name', $data['name'])->count() > 0)
            {
                $error = '该品种已存在';
                return null;
            }
        }
        parent::edit($data, $error, $is_sql);
    }
}
